package com.hspedu.newData.dmsxl.动态规划.打家劫舍;

import org.junit.Test;

/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-04-23 
 * @Version: 1.0
 */

public class LC198打家劫舍 {

    public int rob(int[] nums) {
        int[] dp = new int[nums.length + 1];
        dp[1] = nums[0];

        for (int i = 2; i <= nums.length; i++) {
            dp[i] = Math.max(dp[i-2]+nums[i-1],dp[i-1]);
        }
        return dp[nums.length];
    }


    @Test
    public void test() {
        // 测试代码
        int rob = rob(new int[]{1, 2, 3, 1});
        int rob1 = rob(new int[]{2,7,9,3,1});
        System.out.println("=====");
    }

}
